package com.itheima.topic;

import com.itheima.utils.ConnectionUtil;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

/**
 * @Auther LCSlove
 * @Date 2021-09-06 14:36
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("topic_queue1", true, false, false, null);
        channel.queueDeclare("topic_queue2", true, false, false, null);
        channel.exchangeDeclare("topic_exchange", BuiltinExchangeType.TOPIC);
        channel.queueBind("topic_queue1", "topic_exchange", "item.*");
        channel.queueBind("topic_queue2", "topic_exchange", "order.#");
        String message1 = "hello world,topic 商品添加!!!";
        String message2 = "hello world,topic 商品更新!!!";
        String message3 = "hello world,topic 商品删除!!!";
        String message4 = "hello world,topic 订单添加!!!";
        channel.basicPublish("topic_exchange", "item.insert.123", null, message1.getBytes());
        channel.basicPublish("topic_exchange", "item.update", null, message2.getBytes());
        channel.basicPublish("topic_exchange", "item.delete", null, message3.getBytes());
        channel.basicPublish("topic_exchange", "order.update.123", null, message4.getBytes());
        channel.close();
        connection.close();
    }
}
